/*
 * EventSignAspect.aj
 * 
 *  author: Daniel Rudigier
 *    date: 12.12.2008
 * 
 * 
 */
package at.syncme.aspects;

import at.syncme.framework.Event;

/**
 * sign all created events with the current global virtual time. this problem is
 * neither part of the event class itself nor should any other event creating
 * class always have access to the current game state object, which holds the
 * current global virtual time.
 * 
 * @author Daniel Rudigier
 */
public aspect EventSignAspect extends GameAspect {
    
    private long getCurrentGVT() {
        if (game == null) {
            return 0;
        } else {
            return game.getGs().getGvt();
        }
    }

    /**
     * sign local created events, and always ask the game for the current game-state
     * 
     * reference
     */
    after() returning (Event e): eventCreated() {
        if (e.isLocal()) {
            e.setCreated(getCurrentGVT());
        }
    }
    
    /**
     * sign the event, and always ask the game for the current game-state
     * 
     * reference
     */
    after() returning (Event e): eventAcknowledged() {
        e.setAcknowledged(getCurrentGVT());
    }

}
